package com.bckj.fastboot.upms.biz.service;

import com.bckj.fastboot.upms.api.constant.UpmsCacheConstant;
import com.bckj.fastboot.upms.api.dto.SysDictQuery;
import com.bckj.fastboot.upms.api.dto.SysDictRequest;
import com.bckj.fastboot.upms.api.entity.SysDict;
import com.bckj.fastboot.upms.api.vo.SysDictVO;
import com.bckj.fastboot.upms.biz.repository.SysDictRepository;
import com.bckj.fastboot.upms.biz.convert.SysDictConvert;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;


@Slf4j
@Service
@RequiredArgsConstructor
public class SysDictService {

	private final SysDictRepository sysDictRepository;
	private final SysDictConvert sysDictConvert;

	public List<SysDictVO> findAll(SysDictQuery query) {
		return sysDictRepository.getBaseMapper().findAll(query);
	}

	public boolean save(SysDictRequest request) {
		return sysDictRepository.save(sysDictConvert.request2Bean(request));
	}

	public boolean update(SysDictRequest request) {
		return sysDictRepository.updateById(sysDictConvert.request2Bean(request));
	}

	public SysDictVO details(Long id) {
		return sysDictConvert.bean2VO(sysDictRepository.getById(id));
	}

	public boolean enabled(Long id) {
		return false;
	}

	public boolean remove(Long id) {
		return false;
	}

	@Cacheable(value = UpmsCacheConstant.DICT_TYPE, key = "#p0")
	public List<SysDict> listByType(String type) {
		return sysDictRepository.lambdaQuery().eq(SysDict::getType, type).eq(SysDict::getIsEnable, 1).eq(SysDict::getDeleteFlag, 0).list();
	}

}

